const { db, app } = require("./Mysql_Cont");


interface mysqldb<T> { //泛型接口
    add(sql: string, type: 'POST', portName: string): Object; //添加接口，返回boolean  传入一个sql语句
    delete(sql: string, portName: string, type?: 'get' | 'post'): Object; //删除接口 传入删除语句 和参数
    get(sql: string, portName: string, type?: 'get' | undefined): T;//查询语句，传入sql 并返回 boolean
    update(sql: string, type: 'POST', portName: string): Object;//修改语句，传入sql 并返回 boolean
}




class Mysql<T>{
    add(sql: string, type: "POST", portName: string): Object {
        throw new Error("Method not implemented.");
    }
    delete(sql: string, type: "get", portName: string, cb?: Function): any {
        db({ sql: sql, type: type, connectorName: portName, Timeout: 30000, cb: cb })
    }
    get(sql: string, type: "get", portName: string, cb?: Function): any {

        db({ sql: sql, type: type, connectorName: portName, Timeout: 30000, cb: cb })
    }
    update(sql: string, type: "POST", portName: string): Object {
        throw new Error("Method not implemented.");
    }

}

class getDatas {
    public sql: string | undefined;       //sql语句
    public type: string | undefined; //接口类型
    public connectorName: string; //接口名称

    constructor(prms: { sql: string, type: string, connectorName: string }) {
        this.sql = prms.sql
        this.type = prms.type
        this.connectorName = prms.connectorName
    }
}



let mydb = new Mysql<getDatas>();

// mydb.delete('DELETE FROM `img_html` WHERE `id` = 11689', 'get', '/ppppp');
// mydb.get('SELECT * FROM `img_html`', 'get', '/getdata')

export {mydb}